/**<
13. Create a program which takes in a user's first name then grades for midterm,
 final, and all homework (use vector). Output the final grade based on 40% final, 20%
 midterm, 40% median homework to the nearest x.xx precision
 */

 #include<iostream>
 #include<iomanip>
 #include<string>
 #include<algorithm>
 #include<ios>
 #include<vector>

 using std::cout;       using std::cin;
 using std::endl;       using std::setprecision;
 using std::sort;       using std::string;
 using std::vector;     using std::streamsize;


void FinalGrade(){

      //take users name
     cout << "Please enter your name: " << endl;
     string name;
     cin >> name;

      //show users name
     cout << "Hello " << name << "!" << endl;

     //take final and midterm grade
     cout << "Please enter your final and midterm grades" <<endl;
     double midterm_grade, final_grade;
     cin >> midterm_grade >> final_grade;

     //take homework grades
    cout << "Please enter your homework grades, "
            "enter 'z' when finished." <<endl;

    vector<double> homework;
    double x;

    while(cin >> x){
        homework.push_back(x);
    }

     //compute median homework grade
    typedef vector<double>::size_type vec_sz;
    vec_sz size = homework.size();
    //end the program if there are no values
    if (size == 0){
        cout << endl << "There are no grades. "
        "Please start over";
    }else{

        //sort the grades
        sort(homework.begin(), homework.end());

        //show the sorted grades
        cout << "Sorted homework grades: ";
        for(int i=0;i != homework.size();i++){
            cout << homework[i] << " ";
        }

        //compute the median homeowork grade
        vec_sz mid = size/2;
        double median;
        median = size %2 ==0 ? (homework[mid] + homework[mid-1]) /2
            : homework[mid];

        //compute final grade
        streamsize prec = cout.precision();
        cout << endl << "Your final grade is: " << setprecision(3)
            << 0.2 * midterm_grade + 0.4 * final_grade + 0.4 * median
            << setprecision(prec) << endl;
        //show final grade
    }


}


